import { defineStore } from 'pinia'
import { nextTick, ref } from 'vue'

export default defineStore('token', () => {
    const token = ref<string | null>(null)
    const setToken = (val: string) => (token.value = val)
    const clearToken = async () => {
      token.value = null
      await nextTick()
      uni.clearStorageSync()
    }
    return { token, setToken, clearToken }
  },
  {
    persist: {
      storage: {
        getItem: (key) => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
      },
    },
  },
)
